package tester;

public class TrueFalseQuestion extends Question{
	private boolean correctAnswer;
	
	TrueFalseQuestion(String questionText, String correctAnswer) {
		super(questionText, "Type true or false:", 
				"\\s*([t|T][r|R][u|U][e|E]|[f|F][a|A][l|L][s|S][e|E])\\s*", 
				new String[] {});
		this.correctAnswer = new Boolean(correctAnswer);
	}

	@Override
	protected boolean checkAnswer(String answer) {
		if (!validateAnswer(this.regexp, answer)) {
			return false;
		}
		return (this.correctAnswer == convertAnswer(answer));
	}
	
	protected boolean convertAnswer(String answer) {
		answer  = answer.replaceAll("\\s", "");
		boolean result = new Boolean(answer);
		return result;
	}

}
